package com.trippartner.client.map.view;

import com.google.gwt.maps.client.MapType;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.trippartner.client.map.presenter.CartePresenter.Display;

public class CarteView extends Composite implements Display {
	
	private MapWidget map;

	private final TextBox txtBox;
	
	private final HorizontalPanel hPanel;

	public CarteView() {
		super();
	    //zone de txt pour saisir une adresse.
	    txtBox = new TextBox();
	  //  txtBox.setHeight("17px");
	    Label label = new Label("Adresse :");
	    
	    hPanel = new HorizontalPanel();
	    hPanel.add(label);
	 //   hPanel.setWidth((Window.getClientWidth()) + "px");
	    hPanel.add(txtBox);
	    
	    VerticalPanel vPanel = new VerticalPanel();
	    vPanel.add(hPanel);
	    
	    //pour le designer gwt qui ne sait pas créer un google map dans son editeur.
	    try{
	    map = new MapWidget();
		//map.setHeight((Window.getClientHeight() - offsetTop-hPanel.getOffsetHeight()) + "px");
		map.setUIToDefault();
		map.addMapType(MapType.getHybridMap());
		map.setCurrentMapType(MapType.getHybridMap());
		vPanel.add(map);
	    }
	    catch(Throwable t){
	    	//voir le log d'app gwt.
	    	t.printStackTrace();
	    	vPanel.add(new HTML("Impossible de charger la googleMap Widget"));
	    }
	    
	    
	    initWidget(vPanel);	    
	}

	public void nettoyerLaCarte() {
		map.clearOverlays();
	}

	public Widget asWidget() {
		return map;
	}
	
	public MapWidget getMap() {
		return map;
	}
	
	public int getAdressInputHeight(){
		return hPanel.getOffsetHeight();
	}

}